package com.ttai.presenter.activity;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ttai.model.net.ResponseInfo;
import com.ttai.model.net.SRPOneBean;
import com.ttai.presenter.base.BasePresenter;
import com.ttai.ui.activity.EnterPage;
import com.ttai.untils.SRPClient;
import com.ttai.untils.SRPUtil;

import retrofit2.Call;


public class SRPOnePresenter extends BasePresenter {

    SRPTwoPresenter srpTwoPresenter = new SRPTwoPresenter();
    private SRPClient cli;


    @Override
    protected void showError(String message) {

    }

    @Override
    protected void parseJson(JsonObject json) {
        Gson gson = new Gson();
        SRPOneBean srpOneBean = gson.fromJson(json,SRPOneBean.class);
        String g = srpOneBean.getG();
        String n = srpOneBean.getN();
        String s = srpOneBean.getS();
        Log.i("12", "parseJson: g:"+g+" n:"+n+" s:"+s);
        cli = new SRPClient(EnterPage.enterphonenumber, SRPUtil.fromb64(n),SRPUtil.fromb64(g),SRPUtil.fromb64(s));
        byte[] cex = cli.generateExponential();
        String A = SRPUtil.tob64(cex);
        Log.i("90", "parseJson: A:"+A+" phone:"+EnterPage.enterphonenumber);
        srpTwoPresenter.getClient(cli);
        srpTwoPresenter.srpTwo(A,EnterPage.enterphonenumber);


    }
    public void srpOne(String phone,String equipmentEnvir){
        Call<ResponseInfo> srpone = responseInfoApi.srpone(phone,equipmentEnvir);
        srpone.enqueue(new CallBackAdapter());
    }
}
